package mindshare;


import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.util.Log;

public class ProfileInf {
	public static Usuario usuario=new Usuario();
	private String nickname;
	Context cont;
	List<NameValuePair> params = new ArrayList<NameValuePair>();
	private String name;
	private String studyDegree;
	public static final String KEY_NAME = "name";
	
	public ProfileInf( String nickna, Context c) {
		this.cont = c;
		this.nickname = nickna;
		obtainUserInfo();
	}
	
	
	
	public class GetUserInfo extends LoadContent {
		// Hacer php que saque el nombre de usuario,texto del post, tipo,
		// categoria, idpost padr

		

		public GetUserInfo(Context context, List<NameValuePair> param, String data) {
			super(context, param, data);
		}

		@Override
		protected void onPreExecute() {
		}

		@Override
		protected String doInBackground(String... args) {
			JSONObject json = jParser.makeHttpRequest("http://mindshare.comli.com/profileInfo.php", param);
			JSONArray userInfo;
			JSONArray domainCats;
			JSONArray interestCats;
			try {
				userInfo = json.getJSONArray("personalInfo");
				domainCats = json.getJSONArray("domainCats");
				interestCats = json.getJSONArray("interestCats");
				ArrayList<String> conocimientos= new ArrayList<String>();
				ArrayList<String> intereses= new ArrayList<String>();
				for(int i = 0; i<domainCats.length(); i++){
					Log.d("DOMAIN CATS", "jes cat: "+domainCats.getString(i));	
					conocimientos.add(domainCats.getString(i));
				}
				for(int i = 0; i<interestCats.length(); i++){
					Log.d("DOMAIN CATS", "jes cat: "+interestCats.getString(i));			
					intereses.add(interestCats.getString(i));
				}
				usuario.setConocimientos(conocimientos);
				usuario.setIntereses(intereses);
				
				name = userInfo.getString(0);
				studyDegree = userInfo.getString(1);
				usuario.setNickname(name);
				Log.d("TAG", "jes User name:" + name);
				usuario.setStudyDegree(studyDegree);
				Log.d("TAG", "jes User studyDegree:" + studyDegree);

			} catch (JSONException e) {
				e.printStackTrace();
			} catch (NullPointerException e) {
				e.printStackTrace();
			}

			return null;
		}

		protected void onPostExecute(String file_url) {
		}

	}
	
	public String getName(){
		return name;
	}
	
	public String getStudyDegree(){
		return studyDegree;
	}
	
	public void obtainUserInfo() {
		Log.d("test", "Jes esta n obtainUserInfo");
		params.clear();
		params.add(new BasicNameValuePair("nickname", nickname));
		GetUserInfo gUI = new GetUserInfo(cont, params, ""); 
		gUI.execute();

	}
	
	
}
